﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using IFPRJ.EF.DALayer;
using IFPRJ.EF.DALayer.Providers.Sqlserver;
using IFPRJ.EF.Model;
using IFPRJ.EF.Components;
using System.Web;


namespace IFPRJ.Areas.Admin
{
    public class NewsCatoryController:AdminBaseController
    {
        INewsCatory provider = new NewsCatoryProvider();
        private SelectList GetDropDownList()
        {
            List<SelectListItem> items = new List<SelectListItem>();
            var newscatories = provider.NewsCatoryLoadAll();
            return new SelectList(newscatories, "Id", "Name");
        }

        
        public ActionResult Index()
        {
            var newscatorieslist = provider.NewsCatoryLoadAll();
            this.ViewData["newscatories"] = newscatorieslist;
            return View(new List<News_Catory>(newscatorieslist));
        }

        public ActionResult Create()
        {
            this.ViewData["newscatories"] = GetDropDownList();
            return View();
        }
        [AcceptVerbs(HttpVerbs.Post)]
        [ValidateInput(false)]
        public ActionResult Create(News_Catory _catory, string newscatories)
        {
            _catory.ParentID = Convert.ToInt32(newscatories);
            provider.NewsCatoryCreate(_catory);
            return RedirectToAction("Index");
        }


        public ActionResult Edit(int id)
        {
            News_Catory news_catory = provider.NewsCatoryGetSingleByCatoryId(id);
            this.ViewData["newscatories"] = GetDropDownList();
            return View(news_catory);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        [ValidateInput(false)]
        [HttpPost, ActionName("Edit")]
        public ActionResult EditSave()
        {
            if (ModelState.IsValid)
            {
                //provider.NewsCatoryUpdate();
                return RedirectToAction("Index");
            }
            return RedirectToAction("Index");
        }



        public ActionResult Delete(int id)
        {
            News_Catory deletenews = provider.NewsCatoryGetSingleByCatoryId(id);
            return View(deletenews);
        }

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            News_Catory deleteid = provider.NewsCatoryGetSingleByCatoryId(id);
            provider.NewsCatoryDelete(deleteid);

            return RedirectToAction("Index");
        }
    }
}
